package com.sekill.goods.controller;


import com.sekill.goods.entity.TbSku;
import com.sekill.goods.service.ITbSkuService;
import freemarker.template.Configuration;
import freemarker.template.Template;
import org.apache.commons.io.IOUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
import org.springframework.web.bind.annotation.GetMapping;
import com.sekill.goods.entity.Seckill;
import com.sekill.goods.entity.TbSku;
import com.sekill.goods.service.ISeckillService;
import com.sekill.goods.service.ITbSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.*;

import java.util.List;

/**
 * <p>
 * sku表,该表表示具体的商品实体,如黑色的 64g的iphone 8 前端控制器
 * </p>
 *
 * @author gao
 * @since 2021-06-18
 */
@RestController
@RequestMapping("/tb-sku")
public class TbSkuController {


    @Autowired
    private ITbSkuService iTbSkuService;

    @Autowired
    private ISeckillService iSeckillService;

    /*
    *查询所有商品信息
     */
    @GetMapping("listgoods")
    public List<TbSku> listgoods(){

        List<TbSku> listgoods = iTbSkuService.listgoods();

        return listgoods;
    }



    @GetMapping("getgoods")
    public List<TbSku> getgoods(){
        List<TbSku> list = iTbSkuService.list();

        return list;
    }

    @GetMapping("getByid")
    public boolean getByid(Integer id){
        TbSku goods = iTbSkuService.getById(id);
        Seckill seckill = new Seckill();
        seckill.setSkuId(goods.getId());
        seckill.setTitle(goods.getTitle());
        seckill.setSeckillPrice(new BigDecimal(9.99));
        Date date = new Date();
        GregorianCalendar calendar = new GregorianCalendar();
        Date time = calendar.getTime();
        seckill.setSeckillCreatedate(date);
        seckill.setSeckillEnddate(time);
        seckill.setStatus(1);
        boolean save = iSeckillService.save(seckill);
        return save;
    }

}
